Commit Graph

1064 Commits

Author SHA1 Message Date
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 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
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 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
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
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
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
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
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
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 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 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
Damien George ee4ffc1804 stm32/powerctrl: Add MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET option.
When disabled the bootloader is entered via a direct jump.  When enabled
the bootloader is entered via a system reset then a jump.  It's enabled by
default to retain the existing behaviour, which is the recommended way.

Signed-off-by: Damien George <damien@micropython.org>
2021-05-12 13:44:41 +10:00
David Lechner ca0c75f504 stm32/boards: Change default LSI_VALUE to 32000 for F4 MCUs.
In the STM32 HAL libraries, the default value for LSI_VALUE for F4 MCUs is
32 kHz.

Signed-off-by: David Lechner <david@pybricks.com>
2021-05-04 16:53:40 +10:00
Damien George e9e9c76ddf all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt.
To match mp_sched_exception() and mp_sched_schedule().

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:13:43 +10:00
iabdalkader a1111b83ed stm32/sdio: Allow configuring the SDMMC periph used for SDIO.
This can now be selected by setting MICROPY_HW_SDIO_SDMMC, which defaults
to 1, ie SDMMC1.  The pins can also be selected and default to the standard
C8/C9/C10/C11/C12/D2.
2021-04-30 11:26:04 +10:00
iabdalkader baa712b7f0 stm32/boards/PYBD_SF2: Enable RF switch compile option. 2021-04-30 10:16:15 +10:00
iabdalkader 80788154b3 stm32/sdio: Add functions to re/enable SDIO/SDIOIT. 2021-04-30 01:12:08 +10:00
iabdalkader 4d96786823 stm32/uart: Enable HW flow control for UART 1/5/7/8. 2021-04-30 01:10:02 +10:00
Damien George cf7e71fa43 stm32/sdcard: Allow configuring the SDMMC periph used for SD/MMC card.
This can now be selected by setting MICROPY_HW_SDCARD_SDMMC, which defaults
to 1, ie SDMMC1.  This commit also renames the SD pin configuration macros
from MICROPY_HW_SDMMC2_xxx to MICROPY_HW_SDCARD_xxx, as well as renaming
MICROPY_HW_SDMMC_BUS_WIDTH to MICROPY_HW_SDCARD_BUS_WIDTH.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 00:58:17 +10:00
Damien George 37494b8c8a stm32/mboot: Allow mboot to be placed at any location in flash.
A board can now define MBOOT_TEXT0_ADDR to place mboot at a location other
than 0x08000000.  This can be useful if, for example, there is already a
different bootloader on the device.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 00:42:59 +10:00
Damien George 58be5a5aa3 stm32/mboot: Allow a board to customise the linker scripts.
A board can now define MBOOT_LD_FILES (at the Makefile-level) to specify
custom linker scripts.  And stm32_generic.ld has been split into 2 pieces
so one or the other can be reused (usually stm32_sections.ld wolud be
reused by a board, and stm32_memory.ld redefined).

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 00:42:59 +10:00
Damien George 97f09fda3e stm32/mboot: Fix mp_hal_delay_us() and add mp_hal_ticks_ms().
Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 00:42:59 +10:00
Damien George fd01b6c779 stm32/adc: Allow mboot to use basic ADC functions.
Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 00:42:59 +10:00
Damien George ef2896bdea stm32/mboot: Allow a board to add source files to the build.
A board can now use BUILDING_MBOOT at the Makefile-level to do things
conditional on building mboot, for example add source files to SRC_C.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 00:42:59 +10:00
Damien George 885b246ca9 stm32/boardctrl: Show first reset-mode state on LEDs when selecting.
Commit 1e297c8898 introduced a bug where the
very first reset-mode state on the LEDs was not shown, because prior to
that commit the first reset-mode state was the same as the initial LED
state (green on, others off) and update_reset_mode() was called after
setting this initial LED state.

This is fixed in this commit by changing the update_reset_mode() loop so
that it displays the current reset mode before doing the delay.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 00:32:12 +10:00
Damien George a72b8443ca stm32/boardctrl: Add constants for reset mode values.
And use the same boardctrl.h header for both the application and mboot so
these constants are consistent.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 00:31:35 +10:00
Damien George 647fa63f9c stm32/softtimer: Support static soft timer instances.
This adds support for making static (ie not on the Python GC heap) soft
timers.  This can be useful for a board to define a custom background
handler, or eventually for BLE/network processing to use instead of systick
slots; it will be more efficient using soft timer for this.

The main issue with using the existing code for static soft timers is that
it would combine heap allocated and statically allocated soft_timer_entry_t
instances in the same pairing-heap data structure.  This would prevent the
GC from tracing some of the heap allocated entries (because the GC won't
follow pointers outside the heap).

This commit makes it so that soft timer entries are explicitly marked,
instead of relying on implicit marking by having the root of the pairing
heap in the root pointer section.  Also, on soft reset only the heap-
allocated soft timers are deleted from the pairing heap, leaving the
statically allocated ones.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-29 16:54:35 +10:00
Damien George 89b64478c7 stm32/softtimer: Add support for having a C-based callback.
Signed-off-by: Damien George <damien@micropython.org>
2021-04-29 16:54:35 +10:00
iabdalkader a708848b0c stm32/uart: Fix H7 UART clock source configuration.
Previously to this commit, Usart16ClockSelection was overwritten and
Usart234578ClockSelection was not set.
2021-04-28 00:46:48 +10:00