Commit Graph

1218 Commits

Author SHA1 Message Date
Damien George
6804a8a891 stm32/machine_i2s: Fix 16-bit stereo i2s_frame_map.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-29 11:44:08 +11:00
Damien George
2a91c8a888 stm32/machine_i2s: Allow I2S.deinit to be called multiple times.
In particular, it is called by the constructor if the instance already
exists.  So if the previous instance was deinit'd then it will be deinit'd
a second time.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-29 11:44:08 +11:00
Damien George
c90dfba04c stm32/machine_i2s: Set FullDuplexMode to disabled on F4.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-29 11:44:08 +11:00
iabdalkader
fe8b47e29f ports: Allow boards to define additional network interfaces. 2022-03-24 17:23:28 +11:00
Damien George
66fe3d5cb5 stm32: Support building for STM32F745.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 16:01:09 +11:00
Andrew Leech
bb0ca00b77 stm32/mboot: Verify CRC32 of fsload DFU files before writing. 2022-03-22 15:04:41 +11:00
Andrew Leech
bc856a1e29 stm32/mboot: Verify signature of fsload packed DFU files before writing.
When verifying the DFU contents, the signature of signed/encrypted files is
also now checked in this initial, dry-run stage.
2022-03-22 15:04:37 +11:00
Damien George
80055c2cdc stm32/mboot/fwupdate.py: Simplify calculation of CRC32.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 14:14:31 +11:00
Damien George
bf89e336b9 stm32/boards/PYBD_SF2: Turn on SD card in mboot init if SD enabled.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 13:33:43 +11:00
Damien George
e316306546 stm32/mboot: Add support for reading from SD card.
Tested on PYBV10 and PYBD_SF6, with MBOOT_FSLOAD enabled and programming
new firmware from a .dfu.gz file stored on the SD card.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 13:33:43 +11:00
Damien George
9b07d38c7e stm32/mboot: Add support for 64-bit mboot address space for reads.
If enabled via MBOOT_ADDRESS_SPACE_64BIT (it's disabled by default) then
read addresses will be 64-bit.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 13:33:43 +11:00
Damien George
a92d45c3df stm32/mboot: Always check the magic number to enter filesystem loading.
Even if MBOOT_FSLOAD is disabled, mboot should still check for 0x70ad0080
so it can immediately return to the application if this feature is not
enabled.  Otherwise mboot will get stuck in DFU mode.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 12:49:00 +11:00
Damien George
dc91024a73 stm32/mboot: Add pragma for GCC to ignore array bounds warning.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 12:44:10 +11:00
Damien George
f0be0de341 stm32/dma: Add option to disable auto-DMA-turn-off.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 12:43:53 +11:00
Damien George
63c7593df6 stm32/main: Support SD cards without a partition table.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 12:41:15 +11:00
Damien George
75d2bfcccf stm32/sdcard: Add sdcard_select_sd/mmc functions.
So that C code can select which of SD or MMC to use.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 12:38:45 +11:00
Damien George
7a9cf1f0fb stm32/sdcard: Use mp_hal_pin_input instead of HAL function.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 12:15:36 +11:00
Peter Züger
95ee29f4f4 stm32/mbedtls: Add NULL pointer check in m_free_mbedtls.
According to the C standard the free(void *ptr) function: if ptr is a null
pointer, no action occurs.

Signed-off-by: Peter Züger <zueger.peter@icloud.com>
2022-03-17 13:11:22 +11:00
iabdalkader
a16dcc8136 stm32/boards: Convert F4xx and F7xx to new flash FS config.
Following on from 35e70c1698.

Fixes issue #8390.
2022-03-17 13:06:45 +11:00
Damien George
11b77263ef stm32/moduos: Convert module to use extmod version.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-09 10:03:23 +11:00
Damien George
94077c6402 samd/moduos: Convert module to use extmod version.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-09 10:03:23 +11:00
Damien George
5995fb5261 stm32/mboot: Allow a board more control over entry initialisation.
If MBOOT_BOARD_ENTRY_INIT is defined by a board then that function must now
make sure system clocks are configured, eg by calling mboot_entry_init().

Signed-off-by: Damien George <damien@micropython.org>
2022-02-18 14:59:35 +11:00
Damien George
2b62f12103 stm32/mboot: Allow a board to fully configure system clocks.
If a board wants to customise the clocks it can define the following:

    MBOOT_CLK_PLLM
    MBOOT_CLK_PLLN
    MBOOT_CLK_PLLP
    MBOOT_CLK_PLLQ
    MBOOT_CLK_PLLR (only needed on STM32H7)
    MBOOT_FLASH_LATENCY
    MBOOT_CLK_AHB_DIV
    MBOOT_CLK_APB1_DIV
    MBOOT_CLK_APB2_DIV
    MBOOT_CLK_APB3_DIV (only needed on STM32H7)
    MBOOT_CLK_APB4_DIV (only needed on STM32H7)

Signed-off-by: Damien George <damien@micropython.org>
2022-02-18 14:51:01 +11:00
Christophe Priouzeau
130f7db1fc stm32/boards/NUCLEO_WB55: Add Arduino pin alias definitions.
Fixes issue #8295.

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@foss.st.com>
2022-02-18 14:45:49 +11:00
Damien George
a7530cbc03 stm32/boards/NUCLEO_L432KC: Disable MICROPY_OPT_COMPUTED_GOTO.
To save space, after recent fixes to L4 ADC made it overflow flash.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-04 14:28:21 +11:00
iabdalkader
31f2440388 stm32/adc: Remove obsolete FIRST/LAST GPIO channel macros. 2022-02-04 10:45:11 +11:00
iabdalkader
e5df4a96fa stm32/adc: Fix L4 ADC channel numbers.
Use HAL macro to map decimal numbers to channel numbers.  This is needed
since updating L4 HAL v1.17.0 in a0f5b3148a.

Fixes issue #8233.
2022-02-04 10:42:38 +11:00
Peter D. Gray
ae5f647a2d stm32/system_stm32: Make SystemClock_Config() a weak symbol.
This allows boards to override as needed.
2022-02-04 10:29:53 +11:00
Damien George
e306f2285b stm32/boards/NUCLEO_WL55: Add new board definition.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-04 09:43:43 +11:00
Damien George
e0a0719416 stm32: Add initial support for STM32WL MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-04 09:43:43 +11:00
Damien George
9127e63708 stm32/Makefile: Make stm32lib configurable.
The default stm32lib remains lib/stm32lib, but it can now be easily
overriden at build time by specifying STM32LIB_DIR, or STM32LIB_CMSIS_DIR
and STM32LIB_HAL_DIR.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-04 09:43:43 +11:00
Damien George
e4f59a0020 stm32/rtc: Use LL_RTC functions to simplify some MCU-specific code.
This also fixes a possible race condition when exiting initialisation mode:
reading then writing to ISR (via ISR &= ~RTC_ISR_INIT) will clear any flags
that were set by the hardware between the read and the write.  The correct
way to clear just the INIT bit is to just do a single write via ISR =
~RTC_ISR_INIT, which will not clear any other flags (they must be written
to 0 to clear), and that is exactly what LL_RTC_DisableInitMode does.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-04 08:35:14 +11:00
Damien George
26faf74d52 stm32/mboot: Add support for F469/479 MCUs in fwupdate.py.
And don't assert on the sector number in sector_erase, so it can support
erasing arbitrary sectors.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-03 13:21:57 +11:00
Damien George
4f918f4b26 stm32/mboot: Add MBOOT_BOARD_ENTRY_INIT for a board to add entry code.
Also change the signature of stm32_main to uint32_t, which is what it
should be.

Signed-off-by: Damien George <damien@micropython.org>
2022-02-03 13:20:51 +11:00
Damien George
b8d55d4c52 stm32/mboot: Allow HSI to be used as the main clock source.
Signed-off-by: Damien George <damien@micropython.org>
2022-02-03 13:20:22 +11:00
Damien George
fbd47fc46c ports: Consolidate inclusion of umachine module in built-ins.
The inclusion of `umachine` in the list of built-in modules is now done
centrally in py/objmodule.c.  Enabling MICROPY_PY_MACHINE will include this
module.

As part of this, all ports now have `umachine` as the core module name
(previously some had only `machine` as the name).

Signed-off-by: Damien George <damien@micropython.org>
2022-02-03 10:08:54 +11:00
Herwin Grobben
8f68e26f79 stm32: Add support for G4 MCUs, and add NUCLEO_G474RE board defn.
This commit adds support for the STM32G4 series of MCUs, and a board
definition for NUCLEO_G474RE.  This board has the REPL on LPUART1 which is
connected to the on-board ST-link USB-UART.
2022-02-01 16:21:01 +11:00
Damien George
60e05ae84e stm32/mboot: Compute and check CRC32 of dfu file in fwupdate.py.
Signed-off-by: Damien George <damien@micropython.org>
2022-01-31 18:49:08 +11:00
Damien George
ca1914fb47 stm32/mboot: Support H7 MCUs in fwupdate.py.
And optimise the speed of flash writing.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-31 18:26:55 +11:00
Damien George
29867a2439 stm32/mboot: Include hal_rcc_ex.c in source file list.
It's needed at least on F4 because this file overrides the weak function
HAL_RCC_DeInit() from hal_rcc.c.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-31 18:26:55 +11:00
Damien George
c8c229b96c stm32/mboot: Use PLL3 for USB clock source on H7 MCUs.
PLL3-Q is more reliable than PLL1-Q for the USB clock source when entering
mboot from various reset states (eg power on vs MCU reset).  (It was found
that if the main application used PLL3-Q then sometimes the USB clock
source would stay stuck on PLL3-Q and not switch to PLL1-Q after a reset.)

Other related changes:
- SystemCoreClockUpdate() should be called on H7 because the calculation
  can be involved in some cases.
- __set_PRIMASK(0) should be called because on H7 the built-in ST DFU
  bootloader exits with IRQs disabled.

Signed-off-by: Damien George <damien@micropython.org>
2022-01-31 18:26:55 +11:00
Damien George
c99ed8d6fa stm32/powerctrl: Write bootloader-state as 64-bit word to work on H7.
H7 MCUs have ECC and writes do not go through to SRAM until 64-bits have
been written (on another location is written).  So use 64-bit writes for
the bootloader-state variable so it is committed before the system reset.

As part of this change, the lower byte of the bootloader address in
BL_STATE must now be the magic number 0x5a5 for the state to be valid
(previously this was 0x000 which is not as robust).

Signed-off-by: Damien George <damien@micropython.org>
2022-01-31 18:26:55 +11:00
Damien George
4a4f269a1a stm32/powerctrlboot: Set HAL uwTickPrio variable when needed.
Signed-off-by: Damien George <damien@micropython.org>
2022-01-31 18:26:55 +11:00
Damien George
14becd80c9 stm32/usbd_conf: Set lpm_enable and battery_charging_enable on all MCUs.
Signed-off-by: Damien George <damien@micropython.org>
2022-01-31 16:38:32 +11:00
Herwin Grobben
517e82eb6b stm32/fdcan: Fix naming with regards to G4 series. 2022-01-27 23:06:13 +11:00
Herwin Grobben
160e4d9a6d stm32/fdcan: Fix FIFO1 usage and handling of error interrupts.
The original code used a independent state with regards to the interrupt.
During heavy bus error conditions the internal state could become
out-of-sync with the interrupts.

Further explanation: during the development of an application using CAN
communication, a interrupt-run-away was found in some situations.  It was
found that the error interrupt triggered (Warning, Passive or Bus-Off, all
triggered it) the run-away.  The only recovery was a reset.

Two problems were found:
- the error interrupt is enabled but not cleared in the interrupt routine;
- an internal variable 'State' that was used to track the message received
  state (empty, new, full, overflow) that was not directly related to
  interrupt that indicated the state.

In this commit these issues are fixed by adding more values for the
interrupt reason (warning, passive, bus off) and clearing the error
interrupts, and making the internal state directly dependent on the
interrupt state for received messages.

Furthermore, introducing the FIFO1 in the CAN receive stage, another issue
existed.  Even if the messages are received into the FIFO1 (by selecting
message filtering for FIFO0 and FIFO1), the interrupt firing was indicating
FIFO0 Rx.  The configuration of the interrupts for this is now also fixed.
The CAN peripheral has 2 interrupt lines going into the NVIC controller.
The assignment of the interrupt reasons to these 2 interrupt lines was
missing.  Now the reception of FIFO1 messages triggers the second interrupt
line.  Other interrupts (Rx FIFO0 and bus error) are assigned to the first
interrupt line.

Tested on a Nucleo-G474, and also checked the HAL function to work with the
H7 family.
2022-01-27 23:01:08 +11:00
iabdalkader
a00e1e5735 stm32/dac: Deinit all DACs on soft reset.
DAC timed functions continue to run after a soft reset cycle, using
collected memory in the case of write_timed.
2022-01-27 17:10:39 +11:00
Damien George
79a3158de6 stm32/pin: Change remaining uses of "af" to "alt".
The keyword "af" has been deprecated for some time and "alt" should be used
instead (but "af" still works).

Signed-off-by: Damien George <damien@micropython.org>
2022-01-27 16:44:13 +11:00
Damien George
608d421752 stm32/mboot: Remove custom HAL_RCC_GetHCLKFreq and use HAL provided one.
So that a board can access other HAL_RCC functions if it needs them (this
was not possible previously by just adding hal_rcc.c to the src list for a
board because it would clash with the custom HAL_RCC_GetHCLKFreq function).

Signed-off-by: Damien George <damien@micropython.org>
2022-01-20 16:08:17 +11:00
Damien George
5e506567a3 stm32/mbedtls: Enable MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE.
This adds MBEDTLS_MD_SHA1 to the list of default hashes for TLS 1.2
handshake signatures.  Although SHA-1 is weak, this option is turned on in
the default mbedtls configuration file, and allows better compatibility
with older servers.  In particular it allows an stm32-mbedtls-based client
to connect to an axtls-based client (eg default unix port and esp8266).

Signed-off-by: Damien George <damien@micropython.org>
2022-01-17 17:35:04 +11:00