Commit Graph

843 Commits

Author SHA1 Message Date
Jim Mussared 6f35f214d3 stm32/mpconfigport.h: Add modbluetooth module to stm32. 2019-10-01 09:51:02 +10:00
Jim Mussared d72dbb822c stm32: Provide port-specific implementation for Nimble on STM32. 2019-10-01 09:51:02 +10:00
Andrew Leech 4ba0aff472 stm32/uart: Add RTS/CTS pin configuration support to UART4. 2019-09-27 13:24:01 +10:00
Chris Mason eb12fa3862 stm32/powerctrlboot: Add support for HSI at 8MHz on F0 MCUs.
For use with F0 MCUs that don't have HSI48.  Select the clock source
explicitly in mpconfigboard.h.

On the NUCLEO_F091RC board use HSE bypass when HSE is chosen because the
NUCLEO clock source is STLINK not a crystal.
2019-09-26 17:34:04 +10:00
Chris Mason f16e4be3fa stm32/powerctrlboot: Fix clock and PLL selection for HSI48 on F0 MCUs.
Before this patch the UART baudrate on F0 MCUs was wrong because the
stm32lib SystemCoreClockUpdate sets SystemCoreClock to 8MHz instead of
48MHz if HSI48 is routed directly to SYSCLK.

The workaround is to use HSI48 -> PREDIV (/2) -> PLL (*2) -> SYSCLK.

Fixes issue #5049.
2019-09-26 17:32:22 +10:00
Damien George 3328b7d71f stm32: Support disabling the compiler.
Disable via "#define MICROPY_ENABLE_COMPILER (0)" in the board's
mpconfigboard.h file.
2019-09-26 17:05:40 +10:00
Josh Lloyd 7d58a197cf py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions.
Fixes #5140.
2019-09-26 16:04:56 +10:00
Andrew Leech 2397b44062 stm32/usbd_cdc_interface: Add CTS flow control option for USB VCP.
Enabled by default, but disabled when REPL is connected to the VCP (this is
the existing behaviour).  Can be configured at run-time with, eg:

    pyb.USB_VCP().init(flow=pyb.USB_VCP.RTS | pyb.USB_VCP.CTS)
2019-09-26 13:50:24 +10:00
Damien George 6b4666f8cf stm32/can: Guard header file by MICROPY_HW_ENABLE_CAN.
Because not all MCU series have a CAN peripheral.
2019-09-23 23:45:07 +10:00
Damien George ca8ff99e8c stm32: Use mp_printf with MICROPY_ERROR_PRINTER for uncaught exceptions. 2019-09-23 17:15:07 +10:00
iabdalkader 4f78ba3cf4 stm32/boards/NUCLEO_H743ZI: Enable FDCAN on this board. 2019-09-23 17:00:54 +10:00
iabdalkader f7a07b3605 stm32: Add support for FDCAN peripheral, exposed as pyb.CAN.
The new fdcan.c file provides the low-level C interface to the FDCAN
peripheral, and pyb_can.c is updated to support both traditional CAN and
FDCAN, depending on the MCU being compiled for.
2019-09-23 17:00:54 +10:00
Damien George d06fd384c2 stm32/can: Factor CAN driver into low-level and Python bindings.
can.c now contains the low-level C interface to the CAN peripheral, and
pyb_can.c the Python-level class/methods/constants.
2019-09-23 16:58:08 +10:00
Chris Liechti 6f7e774d12 stm32/machine_i2c: Add ability to specify I2C(4) by name. 2019-09-23 15:08:24 +10:00
iabdalkader 73c94bbbd4 stm32/modusocket: Fix NULL deref when accept() an unbound socket. 2019-09-17 12:30:10 +10:00
Damien George 22099ab88f stm32/machine_adc: Fix build for F4 and L4 MCUs that only have ADC1. 2019-09-12 19:10:12 +10:00
Damien George f66616556d stm32/lwip_inc: Enable LWIP_NETIF_EXT_STATUS_CALLBACK for mDNS.
This feature makes sure that mDNS is automatically restarted when there is
any change event on a netif.
2019-09-12 18:08:50 +10:00
Damien George b0e17bbb9d stm32/lwip_inc: Allocate additional MEMP_SYS_TIMEOUT when mDNS enabled.
Since v2.1 of lwIP mDNS uses a MEMP_SYS_TIMEOUT slot, so allocate an extra
one when this feature is enabled.
2019-09-12 18:05:27 +10:00
Damien George bcaafa3823 stm32/usb: Verify number of used endpoints doesn't exceed maximum. 2019-09-11 15:17:38 +10:00
Damien George 6705767da1 stm32/usb: Add support for VCP+MSC+HID mode, incl 2xVCP and 3xVCP. 2019-09-11 15:17:38 +10:00
cristian cfec054073 stm32/board/NUCLEO_F746ZG: Enable Ethernet periph, lwip and ussl. 2019-09-11 11:20:58 +10:00
Jim Mussared c8c37ca407 stm32/boards/STM32F769DISC: Fix number of SDRAM row bits.
According to the schematic, the SDRAM part on this board is a
MT48LC4M32B2B5-6A, with "Row addressing 4K A[11:0]" (per datasheet).  This
commit updates mpconfigboard.h from 13 to 12 to match.
2019-09-10 23:13:52 +10:00
Christopher Wilson f9d142523c stm32/boards/MIKROE_CLICKER2_STM32: Add MikroElektronika Clicker2 board.
- STM32F407VGT6 (1MB of Flash, 192+4 Kbytes of SRAM)
- 5V (via USB) or Li-Polymer Battery (3.7V) power input
- 2 x LEDs
- 2 x user switches
- 2 x mikroBUS sockets
- 2 x 1x26 mikromedia-compatible headers (52 pins)

https://www.mikroe.com/clicker-2-stm32f4
2019-09-10 13:57:01 +10:00
Damien George 2b07f56c2b stm32/boards/NUCLEO_L073RZ: Fix typo in MCU name. 2019-09-10 11:53:00 +10:00
Chris Wilson a605b53702 stm32/mboot: Support boards with only two LEDs.
Mboot currently requires at least three LEDs to display each of the four
states.  However, since there are only four possible states, the states can
be displayed via binary counting on only 2 LEDs (if only 2 are available).
The existing patterns are still used for 3 or 4 LEDs.
2019-09-10 11:25:56 +10:00
Damien George bd2e46e0a5 stm32/boards/stm32wb55_af.csv: Fix ADC pin-channel function mapping. 2019-09-06 17:56:34 +10:00
Damien George 62fe013a5f stm32/machine_adc: Improve operation of ADC for H7, L4 and WB MCUs. 2019-09-06 17:55:12 +10:00
Damien George ebacdfabb6 stm32/machine_adc: Add machine.ADC class. 2019-09-04 15:40:24 +10:00
Jim Mussared 06661890de stm32/powerctrl: Fix machine.bootloader() for L0 MCUs. 2019-09-04 11:36:53 +10:00
Jim Mussared 8fc00928ea stm32/dma: Fix DMA config for L0 MCUs. 2019-09-03 23:33:09 +10:00
Jim Mussared 74fe841449 docs/library/pyb.DAC.rst: Correct frequency for triangle mode output.
Also correct comments in related code.
2019-09-03 23:25:45 +10:00
Damien George 400a128e11 stm32/stm32_it: Include correct EXTI interrupt handlers for L0 MCUs. 2019-08-29 12:00:18 +10:00
iabdalkader 0bec07f32b stm32/extint: Fix EXTI mapping of PVD and RTC events for H7 MCUs. 2019-08-28 12:53:42 +10:00
Damien George 5789558d60 stm32/boards/PYBD_SF2: Exclude certain things when building mboot. 2019-08-28 12:37:13 +10:00
Damien George 68d74b0074 stm32/mboot/Makefile: Define "BUILDING_MBOOT" when building mboot.
So boards can configure their settings based on whether mboot or the main
firmware is being built.
2019-08-28 12:37:13 +10:00
Damien George b1e04848ef stm32/mphalport: Put PYBD specific MAC code in board specific file. 2019-08-28 12:37:13 +10:00
stijn af5c998f37 py/modmath: Implement math.isclose() for non-complex numbers.
As per PEP 485, this function appeared in for Python 3.5.  Configured via
MICROPY_PY_MATH_ISCLOSE which is disabled by default, but enabled for the
ports which already have MICROPY_PY_MATH_SPECIAL_FUNCTIONS enabled.
2019-08-17 23:23:17 +10:00
Damien George 3eff81288c stm32/i2c: Fix generation of restart condition for hw I2C on F0/F7.
Before this patch I2C transactions using a hardware I2C peripheral on F0/F7
MCUs would not correctly generate the I2C restart condition, and instead
would generate a stop followed by a start.  This is because the CR2 AUTOEND
bit was being set before CR2 START when the peripheral already had the I2C
bus from a previous transaction that did not generate a stop.

As a consequence all combined transactions, eg read-then-write for an I2C
memory transfer, generated a stop condition after the first transaction and
didn't generate a stop at the very end (but still released the bus).  Some
I2C devices require a repeated start to function correctly.

This patch fixes this by making sure the CR2 AUTOEND bit is set after the
start condition and slave address have been fully transferred out.
2019-08-16 13:34:04 +10:00
Damien George 497683b315 gitignore: Put build-*/ pattern in top-level gitignore file. 2019-08-16 00:08:08 +10:00
Damien George 25d3509986 stm32/usbd: Make USB device FIFO sizes dynamically configurable.
Allows to optimise and configure the FIFO sizes depending on the USB device
configuration selected at runtime, eg VCP+MSC vs 3xVCP+MSC.
2019-08-15 13:56:50 +10:00
Damien George 8485b72d0d stm32/boards/NUCLEO_L432KC: Add config for USB VCP support. 2019-08-15 12:46:34 +10:00
Damien George 97e8e036c5 stm32/usbd: Support USB device mode on STM32L432 MCUs. 2019-08-15 12:46:04 +10:00
Damien George bf733c27bb stm32/usbd: Introduce MICROPY_HW_USB_IS_MULTI_OTG to simplify USB config
This is an internal config value that is enabled for MCUs that have
multiple OTG instances, to simplify #if configuration of the USB code.
2019-08-15 12:19:28 +10:00
Damien George ba607809f2 stm32/modpyb: Support building with PY_PYB_LEGACY on and HW_USB_HID off. 2019-08-15 12:03:32 +10:00
Chris Wilson 3d02ebb4e8 stm32/sdcard: Support configuring the SD/MMC bus width to 1 or 4 bits.
Some SD/MMC breakout boards don't support 4-bit bus mode.  This adds a new
macro MICROPY_HW_SDMMC_BUS_WIDTH that allows each board to define the width
of the SD/MMC bus interface used on that board, defaulting to 4 bits.
2019-08-08 12:53:05 +10:00
Damien George 102815f700 stm32/mpconfigport.h: Enable lwIP raw sockets. 2019-08-06 15:56:05 +10:00
Damien George 0e2b224b07 stm32/lwip_inc: Enable raw socket type. 2019-08-06 15:56:05 +10:00
Damien George 473157eeb9 stm32/usbd_hid_interface: Include extra header to build with threading. 2019-07-26 12:44:14 +10:00
Damien George ad0b7cb017 stm32/boards/xxx_WB55: Enable USB HID now that it works on WB MCUs. 2019-07-25 17:49:53 +10:00
Damien George fa07deda9f stm32/usbd_hid_interface: Rewrite USB HID interface code.
The previous version did not work on MCUs that only had USB device mode
(compared to OTG) because of the handling of NAK.  And this previous
handling of NAK had a race condition where a new packet could come in
before USBD_HID_SetNAK was called (since USBD_HID_ReceivePacket clears NAK
as part of its operation).  Furthermore, the double buffering of incoming
reports was not working, only one buffer could be used at a time.

This commit rewrites the HID interface code to have a single incoming
buffer, and only calls USBD_HID_ReceivePacket after the user has read the
incoming report (similar to how the VCP does its flow control).  As such,
USBD_HID_SetNAK and USBD_HID_ClearNAK are no longer needed.

API functionality from the user's point of view should be unchanged with
this commit.
2019-07-25 17:42:17 +10:00
Damien George b1129df478 stm32/dma: Fix re-start of DMA stream by clearing all event flags.
As per the datasheet, all event flags for a stream must be cleared before
enabling it.  Fixes issue #4944 (with DAC.write_timed).
2019-07-25 16:48:26 +10:00
badlyby 3b258ef213 stm32/boards/NUCLEO_F722ZE: Add definition files for new board. 2019-07-25 16:31:36 +10:00
badlyby 09267bb147 stm32/boards/stm32f722.ld: Provide memory regions for internal FS. 2019-07-25 16:31:36 +10:00
badlyby 0da2f6f23a stm32/flashbdev: Support internal filesystem on STM32F722/23/32/33. 2019-07-25 16:31:12 +10:00
Damien George 0c12adca46 stm32/boards/USBDONGLE_WB55: Add definition files for new board. 2019-07-17 17:00:34 +10:00
Damien George d2a8fb747f stm32/boards/NUCLEO_WB55: Add definition files for new board. 2019-07-17 17:00:34 +10:00
Damien George 9849567a06 stm32/boards: Add MCU support files for STM32WB55. 2019-07-17 16:50:42 +10:00
Damien George 59b7166d87 stm32: Add initial support for STM32WBxx MCUs.
This new series of MCUs is similar to the L4 series with an additional
Cortex-M0 coprocessor.  The firmware for the wireless stack must be managed
separately and MicroPython does not currently interface to it.  Supported
features so far include: RTC, UART, USB, internal flash filesystem.
2019-07-17 16:33:31 +10:00
Damien George d42392b9a7 stm32/make-stmconst.py: Allow more variation in parens and int-suffix L. 2019-07-17 16:27:17 +10:00
Damien George 02b2ad4fbd stm32/boards/STM32F769DISC: Fix length of FLASH_APP section.
Fixes issue #4924.
2019-07-17 16:19:50 +10:00
Damien George baea43bba7 stm32/boards/B_L072Z_LRWAN1: Enable USB VCP support. 2019-07-16 14:50:44 +10:00
Damien George 64aebca155 stm32/Makefile: Allow a board to disable float support.
By using "MICROPY_FLOAT_IMPL = none" in its mpconfigboard.mk file.
2019-07-16 14:47:32 +10:00
Damien George 102d9911e9 stm32/mphalport: Fix GPIO clock enable for L0 MCUs. 2019-07-16 14:47:12 +10:00
Damien George 4096fa397b stm32/powerctrlboot: Increase SYSCLK to 32MHz for L0 MCUs. 2019-07-16 14:46:31 +10:00
Damien George 4c1ad1f691 stm32: Add support for USB on L0 MCUs. 2019-07-16 14:45:53 +10:00
Damien George 788e7f50f2 stm32/usbd_cdc_interface: Make CDC TX/RX buffer sizes configurable. 2019-07-16 14:41:59 +10:00
Damien George f302f784e9 stm32/usb: Add config options to disable USB MSC and/or HID.
The new configurations MICROPY_HW_USB_MSC and MICROPY_HW_USB_HID can be
used by a board to enabled or disable MSC and/or HID.  They are both
enabled by default.
2019-07-16 14:39:21 +10:00
Damien George fd49fcb229 stm32/gccollect: Always use MP_STATE_THREAD(stack_top) to get stack top.
In a non-thread build, using &_ram_end as the top-of-stack is no longer
correct because the stack is not always at the very top end of RAM.  See
eg 04c7cdb668 and
3786592097.  The correct value to use is
&_estack, which is the value stored in MP_STATE_THREAD(stack_top), and
using the same code for both thread and non-thread builds makes the code
cleaner.
2019-07-11 17:32:01 +10:00
Damien George a17b901a9e stm32/boards/B_L072Z_LRWAN1: Add definition files for new board. 2019-07-09 12:54:09 +10:00
Damien George 278e9bffe9 stm32/mboot: Update dependencies to enable parallel build with -j. 2019-07-09 11:46:47 +10:00
Damien George 342539bdcc stm32/mboot: Use STARTUP_FILE from stm32lib. 2019-07-09 11:35:47 +10:00
Damien George 5a81d2d6b8 stm32/mboot: Remove use of BSRRL/H for H7 MCUs due to stm32lib update. 2019-07-09 11:34:54 +10:00
Damien George c8f19f1371 stm32/mboot: Make _estack an array to avoid compiler warnings.
The compiler can warn about out-of-bounds array access if _estack is just a
single uint8_t.
2019-07-09 11:33:57 +10:00
Damien George d43dd886a5 stm32/boards/NUCLEO_F413ZH: Remove STARTUP_FILE, it's defined globally.
The Makefile now defines this variable to the correct value (but it can
still be overridden by a board if necessary).
2019-07-09 11:32:12 +10:00
Chris Mason c24d81119c stm32/boards/NUCLEO_L452RE: Add definition files for new board. 2019-07-08 16:50:45 +10:00
Chris Mason 64181b5f76 stm32: Add support for STM32L452 MCUs. 2019-07-08 16:50:19 +10:00
Damien George eea61a09c4 stm32/boards/NUCLEO_F446RE: Enable DAC. 2019-07-08 16:08:40 +10:00
Damien George 5fd62c8992 stm32: Remove SystemInit funcs, use stm32lib versions instead.
stm32lib now provides system_stm32XXxx.c source files for all MCU variants,
which includes SystemInit and prescaler tables.  Since these are quite
standard and don't need to be changed, switch to use them instead of custom
variants, making the start-up code cleaner.

The SystemInit code in stm32lib was checked and is equivalent to what is
removed from the stm32 port in this commit.
2019-07-08 15:23:53 +10:00
Damien George c15dc2c4b9 stm32/powerctrl: Move F0's SystemClock_Config to powerctrlboot.c. 2019-07-08 15:23:53 +10:00
Damien George 21ecf8be5f stm32/powerctrl: Move L0's SystemClock_Config to powerctrlboot.c file. 2019-07-08 15:23:53 +10:00
Damien George 7c2e83324b stm32/boards/NUCLEO_L073RZ: Add definition files for new board. 2019-07-05 17:28:54 +10:00
Damien George 6053e450b8 stm32/mpconfigport.h: Make "framebuf" module configurable by a board. 2019-07-05 17:26:49 +10:00
Damien George 9c096c190c stm32/boards: Add MCU support files for STM32L072. 2019-07-05 17:26:03 +10:00
Damien George 23d9c6a0fd stm32: Add initial support for STM32L0xx MCUs. 2019-07-05 17:24:59 +10:00
Damien George c1a8c7fc09 stm32/boards/PYBD_SFx: Automatically turn on EN_3V3 when powering SD/MMC 2019-07-04 11:11:11 +10:00
Damien George 7f33f158b9 stm32/sdcard: Add hook for a board to power on SD/MMC. 2019-07-04 11:10:54 +10:00
Damien George 1cd2bc066d stm32/boards/PYBD_SFx: Configure EN_3V3 pin as output on boot.
But leave it turned off, the application must turn it on if/when needed.
2019-07-04 11:03:10 +10:00
Damien George afb2e9dd94 stm32/modmachine: Disable IRQs before entering bootloader.
To make sure that the code that enters the bootloader is not interrupted.
2019-07-04 10:49:51 +10:00
Damien George 04da8864e5 stm32/lwip_inc: Define LWIP_NO_CTYPE_H=1 to use lwIP ctype funcs. 2019-07-04 10:36:51 +10:00
Damien George 592f68449d stm32/mpu: Include MPU functions when ETH is enabled. 2019-07-03 23:50:34 +10:00
Damien George 7cf8285ac8 stm32/boards: Remove startup_stm32*.s files now they are in stm32lib. 2019-07-03 23:44:17 +10:00
Damien George 6b6403ce76 stm32/Makefile: Use startup_stm32*.s file from stm32lib.
This means that each MCU now gets a unique IRQ table, eg a specific one for
STM32F405, STM32F411, etc rather than just STM32F4xx.
2019-07-03 23:42:36 +10:00
Damien George 241e577753 stm32/Makefile: Remove Wno-attributes for ll_usb HAL file.
This HAL file is now patched so it doesn't have these warnings.
2019-07-03 23:41:33 +10:00
Damien George 73e8b7e0e4 stm32: Update components to work with new H7xx HAL. 2019-07-03 23:40:49 +10:00
Damien George 3581deec81 stm32/boards/PYBD_SF2: Put mbedtls library code in external QSPI flash.
mbedtls is large and self contained so is a good candidate to be in
external XIP flash, to keep enough spare ROM in internal flash.
2019-07-03 16:50:02 +10:00
Damien George f88cb8a514 stm32/modmachine: Make RTC class available in machine module.
This is a start to make a more consistent machine.RTC class across ports.
The stm32 pyb.RTC class at least has the datetime() method which behaves
the same as esp8266 and esp32, and with this patch the ntptime.py script
now works with stm32.
2019-07-03 16:46:07 +10:00
Damien George 79b6688558 stm32/extint: Simplify bitband support config for different MCUs. 2019-07-03 12:02:58 +10:00
Damien George 14bec7964f stm32/spi: Factor out code to calculate SPI source frequency. 2019-07-03 12:02:46 +10:00
Damien George f114ce0a4b stm32/usb: Add "port" keyword argument to pyb.usb_mode, to select FS/HS.
If the board supports it, the USB port can now be explicitly specified, eg:

    pyb.usb_mode('VCP', port=0).

port=0 is USB FS and port=1 is USB HS.
2019-07-03 11:58:56 +10:00
Damien George 46b3cc4572 stm32/usb: Add support to auto-detect USB interface, either FS or HS.
If both FS and HS USB peripherals are enabled for a board then the active
one used for the REPL will now be auto-detected, by checking to see if both
the DP and DM lines are actively pulled low.  By default the code falls
back to use MICROPY_HW_USB_MAIN_DEV if nothing can be detected.
2019-07-03 11:51:13 +10:00
Damien George 6d2e654b14 stm32/mpconfigport.h: Enable useful networking modules if lwIP enabled. 2019-07-03 11:21:45 +10:00
Damien George d821a27b58 stm32/boards/PYBD_SFx: Put SPI flash to sleep during sleep modes. 2019-07-03 01:27:33 +10:00
Damien George ea033bf25a stm32/powerctrl: Add hooks for a board to perform actions on sleep/wake. 2019-07-03 01:27:33 +10:00
Damien George caabdd99c0 stm32/qspi: Handle bus acquisition.
When going out of memory-mapped mode to do a control transfer to the QSPI
flash, the MPU settings must be changed to forbid access to the memory
mapped region.  And any ongoing transfer (eg memory mapped continuous read)
must be aborted.
2019-07-03 01:27:33 +10:00
Damien George 2034c0a2e3 stm32/qspi: Force a reset of the QSPI peripheral when initialising it.
To ensure it is in a known state on start up.
2019-07-03 01:27:33 +10:00
Damien George 8da39fd182 stm32/qspi: Use MPU to allow access to valid memory-mapped QSPI region.
The Cortex-M7 CPU will do speculative loads from any memory location that
is not explicitly forbidden.  This includes the QSPI memory-mapped region
starting at 0x90000000 and with size 256MiB.  Speculative loads to this
QSPI region may 1) interfere with the QSPI peripheral registers (eg the
address register) if the QSPI is not in memory-mapped mode; 2) attempt to
access data outside the configured size of the QSPI flash when it is in
memory-mapped mode.  Both of these scenarios will lead to issues with the
QSPI peripheral (eg Cortex bus lock up in scenario 2).

To prevent such speculative loads from interfering with the peripheral the
MPU is configured in this commit to restrict access to the QSPI mapped
region: when not memory mapped the entire region is forbidden; when memory
mapped only accesses to the valid flash size are permitted.
2019-07-03 01:27:33 +10:00
Damien George eca4115f66 stm32/sdram: Use MPU helper functions to configure MPU for SDRAM use. 2019-07-03 01:27:33 +10:00
Damien George f7eb2c72f7 stm32/eth: Use MPU helper functions to configure MPU for ETH use. 2019-07-03 01:27:33 +10:00
Damien George 8dcf25e1bd stm32/mpu: Add helper functions for configuring MPU. 2019-07-03 01:27:33 +10:00
Damien George c80614dfc8 ports: Provide mp_hal_stdio_poll for sys.stdio polling where needed. 2019-07-01 17:10:12 +10:00
Chris Mason 3786592097 stm32/boards: Optimise flash and RAM allocation for L4 boards.
Optimisations are:
- Remove FLASH_ISR section since devices with a small flash sector erase
  size don't need special FLASH_ISR handling.  This reduces flash image by
  approx 1.5k.
- Make SRAM2 contiguous with SRAM1 where possible.
- Simplify configuration of 2k RAM buffer used for flash filesystem.

RAM changes with this commit:
- L432: stack   6k -> 10k,  bss + heap   42k ->  52k
- L476: stack  16k -> 30k,  bss + heap   80k ->  96k
- L496: stack 206k -> 16k,  bss + heap  112k -> 302k
2019-07-01 16:57:20 +10:00
Damien George d21d578644 stm32/usb: Fix regression with auto USB PID value giving PID=0xffff.
Commit 9e68eec8ea introduced a regression
where the PID of the USB device would be 0xffff if the default value was
used.  This commit fixes that by using a signed int type.
2019-06-25 15:43:54 +10:00
Damien George 009b1f6559 stm32/boards: Rework all stm32??xx_hal_conf.h files to use common code.
This eliminates a lot of duplicated code in these header files.
2019-06-25 14:18:24 +10:00
Damien George f96f53cd97 stm32/boards: Add stm32??xx_hal_conf_base.h files with common settings.
These are intended to be used by all boards, to reduce the size of a
board's configuration.
2019-06-25 14:18:24 +10:00
Damien George 89ebb3325b stm32/boards/pllvalues.py: Support HSx_VALUE defined without uint32_t. 2019-06-25 14:18:24 +10:00
Damien George 04c7cdb668 stm32: Enter bootloader via a system reset.
Entering a bootloader (ST system bootloader, or custom mboot) from software
by directly branching to it is not reliable, and the reliability of it
working can depend on the peripherals that were enabled by the application
code.  It's also not possible to branch to a bootloader if the WDT is
enabled (unless the bootloader has specific provisions to feed the WDT).

This patch changes the way a bootloader is entered from software by first
doing a complete system reset, then branching to the desired bootloader
early on in the start-up process.  The top two words of RAM (of the stack)
are reserved to store flags indicating that the bootloader should be
entered after a reset.
2019-06-25 14:15:49 +10:00
Damien George 205c6d0dc9 stm32/Makefile: Print info messages about use of mboot/QSPI flash. 2019-06-24 21:59:58 +10:00
Damien George 5da60ff9cb stm32/boards: Enable ussl module via mbedtls for boards with network. 2019-06-24 17:48:28 +10:00
Chris Mason 14cf91f704 stm32: In link script, define start of stack separately from heap end.
Previously the end of the heap was the start (lowest address) of the stack.
With the changes in this commit these addresses are now independent,
allowing a board to place the heap and stack in separate locations.
2019-06-14 15:29:24 +10:00
Damien George 8b18cfedee stm32/usbd_msc: Allow to compile when USB enabled and SD card disabled. 2019-06-11 21:01:14 +10:00
Damien George 53200247b7 stm32/usb: Add "msc" kw-arg to pyb.usb_mode to select MSC logical units.
With this the user can select multiple logical units to expose over USB MSC
at once, eg: pyb.usb_mode('VCP+MSC', msc=(pyb.Flash(), pyb.SDCard())).  The
default behaviour is the original behaviour of just one unit at a time.
2019-06-11 16:22:09 +10:00
Damien George 9e68eec8ea stm32/usb: Use ARG_xxx enums to access kw args in pyb_usb_mode. 2019-06-11 15:50:21 +10:00
Damien George 38bcc99a58 stm32/usbd_msc: Provide Mode Sense response data in MSC interface.
Eventually these responses could be filled in by a function to make their
contents dynamic, depending on the attached logical units.  But for now
they are fixed, and this patch fixes the MODE SENSE(6) responses so it is
the correct length with the correct header.
2019-06-11 15:43:59 +10:00
Damien George 829aa58c5c stm32/usbd_msc: Provide custom irquiry processing by MSC interface.
So the MSC interface can customise the inquiry response based on the
attached logical units.
2019-06-11 15:43:58 +10:00
Damien George 518aa571ab stm32/usbd_msc: Rework USBD MSC code to support multiple logical units.
SCSI can support multiple logical units over the one interface (in this
case over USBD MSC) and here the MSC code is reworked to support this
feature.  At this point only one LU is used and the behaviour is mostly
unchanged from before, except the INQUIRY result is different (it will
report "Flash" for both flash and SD card).
2019-06-11 15:43:15 +10:00
Damien George 62f004ba42 stm32/lwip_inc: Update to enable mDNS, TCP listen backlog, faster DHCP. 2019-06-05 16:14:45 +10:00
Damien George 9e4b3681fd stm32: Support optional lwIP mDNS responder. 2019-06-05 16:14:09 +10:00
Damien George fd839221fd stm32/boards/PYBD_SFx: Enable ussl module using mbedTLS. 2019-06-05 15:38:01 +10:00
Damien George fed4c23590 stm32: Integrate optional mbedTLS component for ussl module.
To use it a board should define MICROPY_PY_USSL=1 and MICROPY_SSL_MBEDTLS=1
at the Makefile level.  With the provided configuration it adds about 64k
to the build.
2019-06-05 15:37:31 +10:00
Damien George ce8262a164 stm32/modnetwork: Replace generic netif NIC polling with specific code.
It doesn't work to tie the polling of an underlying NIC driver (eg to check
the NIC for pending Ethernet frames) with its associated lwIP netif.  This
is because most NICs are implemented with IRQs and don't need polling,
because there can be multiple lwIP netif's per NIC driver, and because it
restricts the use of the netif->state variable.  Instead the NIC should
have its own specific way of processing incoming Ethernet frame.

This patch removes this generic NIC polling feature, and for the only
driver that uses it (Wiznet5k) replaces it with an explicit call to the
poll function (which could eventually be improved by using a proper
external interrupt).
2019-06-03 17:14:34 +10:00
Damien George 62fe47aa3a stm32/boards/PYBD_SFx: Enable CYW43 WLAN driver. 2019-06-03 17:14:34 +10:00
Damien George 8b7409c295 stm32: Integrate in the cyw43 driver and network.WLAN class.
Enable it by setting MICROPY_PY_NETWORK_CYW43=1 at the Makefile level.
2019-06-03 17:14:34 +10:00
Damien George 12ed6f91ee stm32: Add low-level SDIO interface for cyw43 driver. 2019-06-03 16:53:46 +10:00
Damien George 370a8116c4 stm32/mphalport: Add support for having MAC in OTP region. 2019-06-03 16:47:35 +10:00
Damien George 10e173aaea stm32/extint: Add extint_set() function for internal C access to EXTI. 2019-06-03 16:47:35 +10:00
Damien George 345e9864aa stm32/modpyb: Add pyb.country() function to set the country.
To be used for peripherals (like radio) that must be location aware.
2019-06-03 16:47:35 +10:00
Damien George 8f55c74533 stm32/boards: Add board definition files for PYBD -SF2, -SF3, -SF6.
These are core configurations providing PYBv1.x-level features.
2019-05-31 22:44:25 +10:00
Damien George 34cae24e30 stm32/boards/pllvalues.py: Search nested headers for HSx_VALUE defines. 2019-05-31 21:44:53 +10:00
Damien George f8274d5e7d stm32/boards/make-pins.py: Allow pins.csv to skip or hide board-pin name
If the board-pin name is left empty then only the cpu-pin name is used, eg
",PA0".  If the board-pin name starts with a hyphen then it's available as
a C definition but not in the firmware, eg "-X1,PA0".
2019-05-31 21:41:30 +10:00
Damien George 3fc7c8e35c stm32/usb: Include py/mpconfig.h instead of mpconfigboard.h.
Because py/mpconfig.h has header include guards.
2019-05-31 21:39:34 +10:00
Damien George ff91b05cfa stm32/usb: Support up to 3 VCP interfaces on USB device peripheral.
To enable define MICROPY_HW_USB_CDC_NUM to 3.
2019-05-31 11:35:42 +10:00
Damien George 0c29502ad9 stm32/usb: Refactor CDC VCP code to enable N CDC interfaces.
The board config option MICROPY_HW_USB_ENABLE_CDC2 is now changed to
MICROPY_HW_USB_CDC_NUM, and the latter should be defined to the maximum
number of CDC interfaces to support (defaults to 1).
2019-05-30 21:11:04 +10:00
Damien George 0bb6b63e66 stm32/mboot/README: Fix some typos, describe bootloader and fwupdate.py. 2019-05-29 16:26:02 +10:00
Andrew Leech 66bcb5596a stm32/modmachine: In bootloader() disable caches before reset of periphs
Otherwise flushing and disabling the D-cache will give a hard-fault when
SDRAM is used.

Fixes #4818.
2019-05-29 15:50:17 +10:00
Andrew Leech 1470184bdd stm32/sdram: Update MPU settings to block invalid region, change attrs.
Set the active MPU region to the actual size of SDRAM configured and
invalidate the rest of the memory-mapped region, to prevent errors due to
CPU speculation.  Also update the attributes of the SDRAM region as per ST
recommendations, and change region numbers to avoid conflicts elsewhere in
the codebase (see eth usage).
2019-05-24 15:55:00 +10:00
Andrew Leech 4f44778728 stm32/sdcard: Add switch break to ensure only correct SD/MMC IRQ is run. 2019-05-23 21:55:31 +10:00
Damien George c769da1aaa stm32/i2c: Support setting the I2C TIMINGR value via keyword arg.
On MCUs that have an I2C TIMINGR register, this can now be explicitly set
via the "timingr" keyword argument to the I2C constructor, for both
machine.I2C and pyb.I2C.  This allows to configure precise timing values
when the defaults are inadequate.
2019-05-21 13:45:17 +10:00
Damien George ddc657658a stm32/machine_i2c: Simplify ROM initialisation of static HW I2C objects. 2019-05-21 12:38:34 +10:00
Andrew Leech ed2b6ea0a8 stm32/i2c: Make timeout for hardware I2C configurable.
Previously the hardware I2C timeout was hard coded to 50ms which isn't
guaranteed to be enough depending on the clock stretching specs of the I2C
device(s) in use.

This patch ensures the hardware I2C implementation honors the existing
timeout argument passed to the machine.I2C constructor.  The default
timeout for software and hardware I2C is now 50ms.
2019-05-21 12:20:19 +10:00
Damien George 38ac697b45 stm32/machine_i2c: Update to support new C-level I2C API. 2019-05-20 15:04:29 +10:00
Damien George 1f63e9b701 stm32/adc: Fix VBAT_DIV to be 4 for STM32F411.
Fixes issue #4794.
2019-05-20 14:37:28 +10:00
Damien George e1e3704aa1 stm32/modmachine: Create dedicated asm function to branch to bootloader.
Recent gcc versions (at least 9.1) give a warning about using "sp" in the
clobber list.  Such code is removed by this patch.  A dedicated function is
instead used to set SP and branch to the bootloader so the code has full
control over what happens.

Fixes issue #4785.
2019-05-17 17:20:43 +10:00
iabdalkader 746fcea7f8 stm32/boards/NUCLEO_H743ZI: Enable SPI3 on this board. 2019-05-15 16:08:10 +10:00
iabdalkader 1646eff864 stm32/irq: Fix IRQ_ENABLE_STATS stats config to work on all MCUs.
Only the M4 and M7 MCUs have an FPU and FPU_IRQn, and FPU_IRQn is not
always the last entry/IRQ number.
2019-05-15 16:04:01 +10:00
iabdalkader 07af74daef stm32/spi: Enable SPI IRQs and add IRQHandlers for H7 MCUs.
The H7 HAL uses SPI IRQs when the SPI is running in DMA mode.
2019-05-15 15:59:25 +10:00
iabdalkader 123c065131 stm32/dma: Always reset and configure the H7 DMA peripheral.
This is required for the H7 DMA to work.
2019-05-15 15:55:41 +10:00
iabdalkader 7359a9e2f2 stm32/dma: Initialise all members of DMA structs for H7 MCUs. 2019-05-13 12:57:44 +10:00
Andrew Leech 29865e3e58 stm32/rtc: Allow overriding startup timeouts from mpconfigboard. 2019-05-09 12:08:43 +10:00
Damien George b8c74014e4 stm32/usbd_cdc_interface: Don't retransmit chars if USB is reconnected.
Before this change, if the USB was reconnected it was possible that some
characters in the TX buffer were retransmitted because tx_buf_ptr_out and
tx_buf_ptr_out_shadow were reset while tx_buf_ptr_in wasn't.  That
behaviour is fixed here by retaining the TX buffer state across reconnects.

Fixes issue #4761.
2019-05-08 12:45:24 +10:00
Damien George 97753a1bbc stm32: Move factory reset files and code to separate source file.
The new function factory_reset_make_files() populates the given filesystem
with the default factory files.  It is defined with weak linkage so it can
be overridden by a board.

This commit also brings some minor user-facing changes:

- boot.py is now no longer created unconditionally if it doesn't exist, it
  is now only created when the filesystem is formatted and the other files
  are populated (so, before, if the user deleted boot.py it would be
  recreated at next boot; now it won't be).

- pybcdc.inf and README.txt are only created if the board has USB, because
  they only really make sense if the filesystem is exposed via USB.
2019-05-07 13:59:51 +10:00
Damien George 34942d0a72 stm32/machine_uart: Change default UART timeout to 0, for non blocking.
It's more common to need non-blocking behaviour when reading from a UART,
rather than having a large timeout like 1000ms (the original behaviour).
With a large timeout it's 1) likely that the function will read forever if
characters keep trickling it; or 2) the function will unnecessarily wait
when characters come sporadically, eg at a REPL prompt.
2019-05-07 13:56:42 +10:00
Chris Mason 2a791170ce stm32/boards: Add NUCLEO_F413ZH board configuration.
The alternate function pin allocations are different to other NUCLEO-144
boards.  This is because the STM32F413 has a very high peripheral count:
10x UART, 5x SPI, 3x I2C, 3x CAN.  The pinout was chosen to expose all
these devices on separate pins except CAN3 which shares a pin with UART1
and SPI1 which shares pins with DAC.
2019-05-02 16:33:30 +10:00
Chris Mason 1b956ec817 stm32: Add support for F413 MCUs.
Includes:
- Support for CAN3.
- Support for UART9 and UART10.
- stm32f413xg.ld and stm32f413xh.ld linker scripts.
- stm32f413_af.csv alternate function mapping.
- startup_stm32f413xx.s because F413 has different interrupt vector table.
- Memory configuration with: 240K filesystem, 240K heap, 16K stack.
2019-05-02 16:26:53 +10:00
Damien George a974f2dc6e stm32/flash: Fix bug computing page number for L432 page erase. 2019-05-02 14:53:26 +10:00
Damien George 3fbf32b947 stm32/powerctrl: Support changing frequency when HSI is clock source.
This patch makes pllvalues.py generate two tables: one for when HSI is used
and one for when HSE is used.  The correct table is then selected at
compile time via the existing MICROPY_HW_CLK_USE_HSI.
2019-05-02 13:00:00 +10:00
Damien George cbeac903e8 stm32/main: Increase default UART REPL rx buffer from 64 to 260 bytes.
This allows the UART to buffer at least 256 bytes (taking into account the
extra byte needed by the ring buffer, and word alignment).
2019-05-01 14:53:21 +10:00
Damien George ff0306dfa5 stm32/usb: Remove mp_hal_set_interrupt_char now that it's reset at boot. 2019-05-01 13:08:05 +10:00
Damien George 8031b7a25c stm32/powerctrl: Deselect PLLSAI as 48MHz src before turning off PLLSAI.
On the STM32F722 (at least, but STM32F767 is not affected) the CK48MSEL bit
must be deselected before PLLSAION is turned off, or else the 48MHz
peripherals (RNG, SDMMC, USB) may get stuck without a clock source.

In such "lock up" cases it seems that these peripherals are still being
clocked from the PLLSAI even though the CK48MSEL bit is turned off.  A hard
reset does not get them out of this stuck state.  Enabling the PLLSAI and
then disabling it does get them out.  A test case to see this is:

    import machine, pyb
    for i in range(100):
        machine.freq(122_000000)
        machine.freq(120_000000)
        print(i, [pyb.rng() for _ in range(4)])

On occasion the RNG will just return 0's, but will get fixed again on the
next loop (when PLLSAI is enabled by the change to a SYSCLK of 122MHz).

Fixes issue #4696.
2019-04-29 16:31:32 +10:00
Andrew Leech 70a28e3ad9 stm32/usb: Add USB device mode for VCP+VCP without MSC.
Selectable via pyb.usb_mode('VCP+VCP').
2019-04-28 21:31:47 +10:00
Damien George 0646e607b5 ports: Convert to use pyexec_file_if_exists() to execute boot/main.py.
The stm32 and nrf ports already had the behaviour that they would first
check if the script exists before executing it, and this patch makes all
other ports work the same way.  This helps when developing apps because
it's hard to tell (when unconditionally trying to execute the scripts) if
the resulting OSError at boot up comes from missing boot.py or main.py, or
from some other error.  And it's not really an error if these scripts don't
exist.
2019-04-26 15:22:14 +10:00
Damien George f66c4cbfa6 stm32/usbdev: Make USB device descriptors at runtime rather than static. 2019-04-26 10:07:49 +10:00
Damien George aa7b32c811 stm32/dac: Rework DAC driver to use direct register access.
This patch makes the DAC driver simpler and removes the need for the ST
HAL.  As part of it, new helper functions are added to the DMA driver,
which also use direct register access instead of the ST HAL.

Main changes to the DAC interface are:

- The DAC uPy object is no longer allocated dynamically on the heap,
  rather it's statically allocated and the same object is retrieved for
  subsequent uses of pyb.DAC(<id>).  This allows to access the DAC objects
  without resetting the DAC peripheral.  It also means that the DAC is only
  reset if explicitly passed initialisation parameters, like "bits" or
  "buffering".

- The DAC.noise() and DAC.triangle() methods now output a signal which is
  full scale (previously it was a fraction of the full output voltage).

- The DAC.write_timed() method is fixed so that it continues in the
  background when another peripheral (eg SPI) uses the DMA (previously the
  DAC would stop if another peripheral finished with the DMA and shut the
  DMA peripheral off completely).

Based on the above, the following backwards incompatibilities are
introduced:

- pyb.DAC(id) will now only reset the DAC the first time it is called,
  whereas previously each call to create a DAC object would reset the DAC.
  To get the old behaviour pass the bits parameter like: pyb.DAC(id, bits).

- DAC.noise() and DAC.triangle() are now full scale.  To get previous
  behaviour (to change the amplitude and offset) write to the DAC_CR (MAMP
  bits) and DAC_DHR12Rx registers manually.
2019-04-24 15:51:19 +10:00
Damien George 8402c26cfa stm32/powerctrl: Enable EIWUP to ensure RTC wakes device from standby. 2019-04-18 17:15:11 +10:00
Damien George 11657f2f20 stm32/system_stm32f0: Add support for using HSE and PLL as SYSCLK.
To configure the SYSCLK on an F0 enable one of:

    MICROPY_HW_CLK_USE_HSI48
    MICROPY_HW_CLK_USE_HSE
    MICROPY_HW_CLK_USE_BYPASS
2019-04-18 16:00:45 +10:00
Damien George f1774fa049 stm32/system_stm32f0: Enable PWR clock on startup.
To be consistent with how F4/F7/H7/L4 works in system_stm32.c.  The power
control peripheral is needed at least for the RTC.
2019-04-18 15:36:59 +10:00
Damien George 194d6b6788 stm32/timer: Correctly initialise extended break settings on F7/H7/L4.
Fixes issue #4693.
2019-04-15 11:41:03 +10:00
Damien George fd112239d6 stm32/rtc: Remove non-ASCII mu-character from source code comment.
And fix a typo in the comment on this line.
2019-04-12 11:32:24 +10:00
Damien George fc9f2ff0cd stm32/rtc: Remove unused LSE detection code. 2019-04-11 12:14:21 +10:00
Damien George 46e5d6b889 stm32/rtc: Add auto-LSE-bypass detection with fallback to LSE then LSI.
If MICROPY_HW_RTC_USE_BYPASS is enabled the RTC startup goes as follows:
- RTC is started with LSE in bypass mode to begin with
- if that fails to start (after a given timeout) then LSE is reconfigured
  in non-bypass
- if that fails to start then RTC is switched to LSI
2019-04-11 12:09:21 +10:00
Damien George 358364b45e stm32/boards/NUCLEO_L432KC: Disable complex nos and default frozen mods.
To save space, since this board only hase 256k of flash.
2019-04-09 11:23:08 +10:00
Damien George 4831e38c7e stm32/boards/NUCLEO_H743ZI: Add config options to support mboot. 2019-04-08 14:34:37 +10:00
Damien George fd13ce5e60 stm32/mboot: Add support for H7 MCUs, with H743 flash layout. 2019-04-08 14:33:57 +10:00
Damien George ae1e18a346 stm32/usbd_conf: Add support for USB HS peripheral on H7 MCUs. 2019-04-08 14:30:16 +10:00
Damien George 2c3fa4ad82 stm32/i2cslave: Add support for H7 MCUs. 2019-04-08 14:28:45 +10:00
Damien George fd523c53c3 stm32/network_wiznet5k: Automatically set MAC if device doesn't have one 2019-04-05 22:37:06 +11:00
Damien George 4f936afc44 stm32/network_wiznet5k: Add ability to set the MAC address. 2019-04-05 22:35:04 +11:00
Damien George 4410efc1e3 stm32/network_wiznet5k: Add ability to trace Ethernet TX and RX frames.
Via: nic.config(trace=2|4)
2019-04-05 22:33:49 +11:00
Damien George 83f3c29d36 stm32/moduos: Allow to compile again without USB enabled. 2019-04-01 17:11:39 +11:00
Damien George 7ce2a08231 stm32: Add support for MMC driver, exposed via pyb.MMCard class.
Enable it via MICROPY_HW_ENABLE_MMCARD.
2019-04-01 17:04:43 +11:00
Damien George 9670b26526 stm32: Rename MICROPY_HW_HAS_SDCARD to MICROPY_HW_ENABLE_SDCARD.
For consistency with the majority of other MICROPY_HW_ENABLE_xxx macros.
2019-04-01 15:21:26 +11:00
Damien George 7b5bf5f6fd stm32/uart: Handle correctly the char overrun case of RXNE=0 and ORE=1.
Fixes issue #3375.
2019-04-01 13:40:35 +11:00
roland van straten edd0e0f93d stm32/timer: Expose the PWM BRK capability of Timer 1 and 8.
The break mode is configurable via the 'brk' keyword to the Timer
constructor and init method.  It's disabled by default.
2019-04-01 13:30:37 +11:00
Andrew Leech 9d6f70f715 stm32: Make default USB_VCP stream go through uos.dupterm for main REPL.
Use uos.dupterm for REPL configuration of the main USB_VCP(0) stream on
dupterm slot 1, if USB is enabled.  This means dupterm can also be used to
disable the boot REPL port if desired, via uos.dupterm(None, 1).

For efficiency this adds a simple hook to the global uos.dupterm code to
work with streams that are known to be native streams.
2019-04-01 13:04:05 +11:00
Boris Vinogradov 6947dff7da stm32/Makefile: Allow to override CROSS_COMPILE with included Makefile. 2019-03-29 11:34:05 +11:00
Boris Vinogradov 1a608ce1e8 stm32/boards/STM32L476DISC: Enable servo support on STM32L476DISC board. 2019-03-28 15:35:58 +11:00
Damien George 781947afdc stm32/mpconfigport.h: Remove malloc/free/realloc helper macros.
These macros are unused, and they can conflict with other entities by the
same name.  If needed they can be provided as static inline functions, or
just functions.

Fixes issue #4559.
2019-03-26 18:42:19 +11:00
roland van straten d396a7e10d stm32/system_stm32: Provide default value for HSI calibration.
If HSI is used the calibration value must be valid.  Fixes #4596.
2019-03-26 17:10:21 +11:00
Dave Hylands ec6e62efc2 stm32/mboot: Set USE_MBOOT=1 by default in the Makefile.
This allows boards that need USE_MBOOT to be built properly whether or not
USE_MBOOT=1 is specified when building mboot.
2019-03-18 14:01:43 +11:00
roland van straten c9eb7eb449 stm32/stm32_it: Guard UART7_IRQHandler with check for UART7 define.
All STM32 with a UART7 also have a UART8 and vice versa, but this change
improves readability and allows for them to be independent in the future.
2019-03-14 14:02:21 +11:00
Damien George c7d19dc0ad ports/{stm32,esp8266}: Set mpy-cross native arch for frozen native code. 2019-03-14 12:22:49 +11:00